﻿using UnityEngine;
using System.Collections;

public class MessageTabBar : ObjectBase
{
	MessageTabBarButton[] m_messageTabBarButton;

	int m_selectedIndex = 0;
	public int SelectedIndex
	{
		get { return m_selectedIndex; }
		set { if (m_selectedIndex == value) return; m_selectedIndex = value; }
	}

	void Awake()
	{
		m_messageTabBarButton = transform.GetComponentsInChildren<MessageTabBarButton>();
		for (int i = 0; i < m_messageTabBarButton.Length; i++)
		{
			m_messageTabBarButton[i].ButtonIndex = i;
			m_messageTabBarButton[i].TabBar = this; 
		}

		if (m_messageTabBarButton.Length > 0)
		{
			m_messageTabBarButton[m_selectedIndex].IsChecked = true;
		}
	}

	public void SelectTab(int buttonIndex)
	{
		if (m_selectedIndex == buttonIndex)
			return;

		m_selectedIndex = buttonIndex;

		for (int i = 0; i < m_messageTabBarButton.Length; i++)
		{
			if (m_selectedIndex == m_messageTabBarButton[i].ButtonIndex)
			{
				m_messageTabBarButton[i].IsChecked = true;
			}
			else
			{
				m_messageTabBarButton[i].IsChecked = false;
			}
		}
	}
}